package com.klb.tools;

import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.io.DataInputStream;
import java.io.IOException;

/**
 * Created by fujia on 2016/6/19.
 */
public class PostValue {
    public static JSONObject getJsonObject(){
        HttpServletRequest request = ServletActionContext.getRequest();

        try {
            int totalbytes = request.getContentLength();
            byte[] dataOrigin = new byte[totalbytes];
            DataInputStream in = new DataInputStream(request.getInputStream());
            in.readFully(dataOrigin);
            in.close();
            String str = new String(dataOrigin);
            JSONObject jsonObject = JSONObject.fromObject(str);

            return jsonObject;

        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}
